<?php
	include_once("../persistent/BaseObject.php");
	
	class Book extends BaseObject
	{
		//public Cover;
		public $Bookname;
		public $AuthorName;
		public $AuthorBrief;
		public $UploaderID;
		public $Translator;
		public $Publishing;
		public $Pages;
		public $Price;
		public $ContentBrief;
		
		public function __construct($d)
		{
			$this->tableName = "Books";
			parent::__construct($d);	
		}		
		
		public function findValueByBookname($bookname){
			$con = $this->openDB();
			
			// 找出Username的条目
			$sql = "SELECT * FROM $this->tableName
			WHERE Bookname = '$bookname'";
			
			return mysql_fetch_array($this->startSQL($sql,$con));
		}
		
		// find the first N books in the booklist
		public function findNBooks($N){
			$con = $this->openDB();
			
			$sql = "SELECT * FROM $this->tableName
			LIMIT $N";
			
			return $this->startSQL($sql,$con);
		}
		
		// find all the books of the current user
		public function findBooklistByUserID($userID){
			$con = $this->openDB();
			
			$sql = "SELECT * FROM $this->tableName
			WHERE UploaderID = '$userID'";
			
			return $this->startSQL($sql,$con);
		}
		
		// find the first N books of the current user
		public function findNBooksByUserID($userID, $N){
			$con = $this->openDB();
			
			$sql = "SELECT * FROM $this->tableName
			WHERE UploaderID = '$userID'
			LIMIT $N";
			
			return $this->startSQL($sql,$con);
		}
	}
?>
